<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <!-- 引入Vue 2 CDN -->
  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
</head>

<body>
  <div id="app"></div>
  <script>
    const { createApp, ref } = Vue
    var app = new Vue({
      el: "#app",
      // 对象格式
      data: {
        foo: "foo"
      },
      // 函数格式
      // data() {
      //   return {
      //     foo: "foo"
      //   }
      // }
      // 对象格式
      data: {
        foo: 'foo'
      }
    })

    // 模仿组件构造函数，定义data属性，采用对象的形式
    function Component() { }
    Component.prototype.data = {
      count: 0
    }
    // 创建两个实例
    const componentA = new Component()
    const componentB = new Component()
    // 修改componentA中data属性的值，componentB中data属性的值也发生了改变
    console.log(componentB.data.count)  // 0
    componentA.data.count = 1
    console.log(componentB.data.count)  // 1


    function ComponentFun() {
      this.data = this.data()
    }
    ComponentFun.prototype.data = function () {
      return {
        count: 0
      }
    }// 创建两个实例
    const componentFunA = new ComponentFun()
    const componentFunB = new ComponentFun()
    console.log(componentFunA.data.count)
    componentFunA.data.count = 1
    console.log(componentFunB.data.count) 
  </script>
</body>

</html>